$(function(){
      var curData=JSON.parse(sessionStorage.getItem('curData'));
      console.log(curData)
      /*获取验证码*/
      $('.getYZMBtn').click(function(){
      	var zhi = $(this).text();
         	var regex = /^[1][3,4,5,7,8][0-9]{9}$/; 
            var myPhone=$('#userPhone').val();
            if($('#userPhone').val().length!==0&&regex.test(myPhone)==true){
            		if(zhi == "获取验证码"){
					      	var sum = 60;
					      	var count = 1;
										
											 ym.ajax({
			                  url: "/base/getRandom",
			                  param:{
			                        phone:$('#userPhone').val()
			                  },
			                  success: function (data) {
			                  		if(data.res == 1){
			                  			var i = setInterval(function (){
											if (count > 59){
												$(".getYZMBtn").text('获取验证码');
												clearInterval(i);
											} else {
													$(".getYZMBtn").text('剩余' + parseInt(sum - count) + '秒');
											}
												count++;
											}, 1000);	
			                  		}else if(data.res == 0){
			                       	 $("#ceng").modal('open');
			                       	 $('#info-text').html(data.resMsg);
			                       	 window.setTimeout(function(){
			                       	 	$("#ceng").modal('close');
			                       	    $('#info-text').html();
			                       	 },500)
			                       }
			                  	}
			                  }); 
				      	}
                 
                 
            }else{
             $('#userPhone').val()
             $("#ceng").modal('open');
							 $('#info-text').html('手机格式不正确');
							 window.setTimeout(function(){
							  $("#ceng").modal('close');
							    $('#info-text').html();
							 },500)
            }
      })   
	
	/*提交表单注册用户*/
	$('#subBtn').click(function(){
		$('#subBtn').attr('disabled','disabled');
		var dataJson={
			userPhone:$('#userPhone').val(),
                  userId:curData.userId
		}
		ym.ajax({
            url: "/user/updateUser",
            param:dataJson,
            success: function (data) {
            	$('#subBtn').removeAttr('disabled','disabled');
            	if(data.res!==0){
                       $("#ceng").modal('open');
			             $('#info-text').html('修改成功');
			             window.setTimeout(function(){
			              $("#ceng").modal('close');
			                $('#info-text').html();
			             },500)
                        window.setTimeout(function(){
                              window.location.href='../html/personal.html';
                        },1000)
                        
            	}else{
            		console.log(data.resMsg);
            	}
            }
         });
	})
})